﻿using KinonekoSoftware.CodariaDB.Documents.Theories.Elements;
using KinonekoSoftware.Studio.Models.Theories;

namespace KinonekoSoftware.Studio.Pages.Theories.Elements
{
    public class TemplatedElementEditorViewModel : TabViewModelCore
    {
        private TheoryOfElementPresenter _element;


        protected override void OnSnapshot(SnapshotMessage message)
        {
            PushToView(message);
        }

        protected override void OnReceive(PageContext context)
        {
            if (context.Has(ContextBase.Key_Value))
            {
                TargetObject = context.GetObject<TheoryOfElementPresenter>(ContextBase.Key_Value);
            }
            
            base.OnReceive(context);
        }

        public TheoryOfElementPresenter TargetObject
        {
            get => _element;
            private set
            {
                _element = value;
                
                RaiseUpdated(nameof(Image));
                RaiseUpdated(nameof(Icon));
                RaiseUpdated(nameof(Intro));
                RaiseUpdated(nameof(Name));
                RaiseUpdated(nameof(Foreground));
                RaiseUpdated(nameof(Background));
            }
        }
        
        public string Image
        {
            get => TargetObject.Image;
            set
            {
                TargetObject.Image = value;
                RaiseUpdated();
            }
        }
        
        public string Icon
        {
            get => TargetObject.Icon;
            set
            {
                TargetObject.Icon = value;
                RaiseUpdated();
            }
        }

        public string Name
        {
            get => TargetObject.Name;
            set
            {
                TargetObject.Name = value;
                RaiseUpdated();
            }
        }

        public string Intro
        {
            get => TargetObject.Intro;
            set
            {
                TargetObject.Intro = value;
                RaiseUpdated();
            }
        }

        public string Foreground
        {
            get => TargetObject.Foreground;
            set
            {
                TargetObject.Foreground = value;
                RaiseUpdated();
            }
        }
        
        public string Background
        {
            get => TargetObject.Background;
            set
            {
                TargetObject.Background = value;
                RaiseUpdated();
            }
        }
    }
}